//数据库操作函数，每个函数都会返回promise
import * as mongoose from 'mongoose';

export class Operater
{
    /**增加一条数据 */
    public static addDoc(doc:mongoose.Model<mongoose.Document>,obj:Object):Promise<mongoose.Document>
    {
        return doc.create(obj);
    }
    /**删除一条数据 */
    public static removeDoc(doc:mongoose.Model<mongoose.Document>,id:Object):Promise<mongoose.Document>
    {
        let p = doc.findByIdAndRemove(id);
        return p.exec();
    }
    /**更新一条数据 */
    public static updateDoc(doc:mongoose.Model<mongoose.Document>,id:Object,obj:Object):Promise<mongoose.Document>
    {
        let p = doc.findByIdAndUpdate(id,obj);
        return p.exec();
    }
    /**根据id查询 */
    public static query(doc:mongoose.Model<mongoose.Document>,id:Object):Promise<mongoose.Document>
    {
        let p = doc.findById(id);
        return p.exec();
    }

    public static queryByFactor(doc:mongoose.Model<mongoose.Document>,obj:Object):Promise<mongoose.Document[]>
    {
        console.warn('queryByFactor:',obj);
        let p = doc.find(obj);
        return p.exec();
    }

    public static AccountEntity:mongoose.Model<mongoose.Document>;
}
